package tests;

import huffman.Hzip;
import junit.framework.TestCase;

import java.io.File;
import java.io.FileInputStream;
import java.util.zip.Adler32;
import java.util.zip.Checksum;

/**
 * author:          alexander
 * version:         1.0
 * *************************************************
 * ** CreationDate:  12/9/12 6:11 PM
 * ** Project:       Leertaak 3 File Compression
 * ** Package:       huffman
 * ** Classname:     HzipTest
 * *************************************************
 */
public class HzipTest extends TestCase {

	private final String INPUTFILE = "H:\\testA";


	public void test_Hzip() throws Exception {
		byte[] b;
		Checksum c = new Adler32();

		Hzip.compress(INPUTFILE + ".dat");

		//----------> get checksum from origional input file
		FileInputStream fis = new FileInputStream(new File(INPUTFILE + ".dat"));
		b = new byte[fis.available()];
		fis.read(b);

		c.update(b, 0, b.length);
		long origional_checksum = c.getValue();

		//<----------END input checksum--------------


		Hzip.uncompress(INPUTFILE + ".dat.huf");

		//----------> get checksum from decompressed input file
		fis = new FileInputStream(new File(INPUTFILE + ".dat.uc"));
		b = new byte[fis.available()];
		fis.read(b);
		c.reset();
		c.update(b, 0, b.length);
		long decompressed_checksum = c.getValue();


		//<---------------END decompressed checksum----------------
		assertEquals(origional_checksum, decompressed_checksum);


	}


}
